package com.tongy.activity;

import java.lang.reflect.Array;

import android.app.Activity;

public class LightMatrices {
	public static int MAX_HEIGHT = 5;
	public static int MAX_WIDTH = 5;
	public Activity m_attachActivity;
	public int[][] m_nArray;
	public int m_nCurLevel;

	public LightMatrices(Activity paramActivity, int level) {
		this.m_attachActivity = paramActivity;
		this.m_nCurLevel = level;
		MAX_HEIGHT = m_nCurLevel;
		MAX_WIDTH = m_nCurLevel;
		int[] arrayOfInt = new int[2];
		arrayOfInt[0] = MAX_WIDTH;
		arrayOfInt[1] = MAX_HEIGHT;

		this.m_nArray = ((int[][]) Array.newInstance(Integer.TYPE, arrayOfInt));
		resetGame();
	}

	public void resetGame() {
		for (int i = 0; i < LightMatrices.MAX_WIDTH; ++i) {
			for (int j = 0; j < LightMatrices.MAX_HEIGHT; ++j) {
				m_nArray[i][j] = 0;
			}
		}
	}

	public boolean checkResult() {
		boolean result = true;
		for (int i = 0; i < LightMatrices.MAX_WIDTH; ++i) {
			for (int j = 0; j < LightMatrices.MAX_HEIGHT; ++j) {
				if (m_nArray[i][j] != 1) {
					result = false;
					break;
				}
			}
		}
		return result;
	}

	public boolean onBtnClick(int x, int y) {
		changeMatrices(x, y);
		if (x - 1 >= 0)
			changeMatrices(x - 1, y);
		if (x + 1 < MAX_WIDTH)
			changeMatrices(x + 1, y);
		if (y - 1 >= 0)
			changeMatrices(x, y - 1);
		if (y + 1 < MAX_HEIGHT)
			changeMatrices(x, y + 1);
		return true;
	}

	public boolean changeMatrices(int x, int y) {
		if (this.m_nArray[x][y] != 0) {
			this.m_nArray[x][y] = 0;
		} else {
			this.m_nArray[x][y] = 1;
		}
		return true;
	}
}
